﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Microsoft.Xna.Framework.Net;
using Microsoft.Xna.Framework.Storage;

namespace ScorchedTanks
{
     public enum CameraMode
    {
        FirstPerson,
        ThirdPerson
    }

     public class Camera
     {
         Vector3 position = Vector3.Zero;
         Vector3 goingto;
         Vector3 forward = Vector3.UnitZ;
         Vector3 up = Vector3.UnitY;
         Vector3 left = -Vector3.UnitX;
         Actor3d mActor;

         Matrix projection;
         public Matrix viewMatrix;

         public bool readyToexit = false;

         public CameraMode mCameraMode; //

         public Camera()
         {
             mCameraMode = CameraMode.ThirdPerson;

         }

         public void setActor(Actor3d actor)
         {
             mActor = actor;
             position = mActor.position - (mActor.direction) + 2 * up;
         }

         public void SwitchMode()
         {
             if (mCameraMode == CameraMode.FirstPerson)
             {
                 mCameraMode = CameraMode.ThirdPerson;
             }
             else
             {
                 mCameraMode = CameraMode.FirstPerson;
             }
         }

         public void update(float dTime)
         {

             if (mActor != null)
             {
                 if (mCameraMode == CameraMode.ThirdPerson)
                 {
                     Vector3 dir = mActor.direction;
                     dir.Normalize();
                     position = mActor.position - (dir * 50) + 10 * up;
                     forward = mActor.direction;
                 }
                 else
                 {
                     position = mActor.position;
                     forward = mActor.direction;
                 }
             }
             if (mCameraMode == CameraMode.ThirdPerson)
             {

             }
         }

         public Vector3 GetPosition()
         {
             return position;
         }

         public void SetPosition(Vector3 v) {
             position = v;
         }

         public void SetPosition(float x, float y, float z) {
             position.X = x;
             position.Y = y;
             position.Z = z;
         }

         public Vector3 GetLookAt()
         {
             return mActor.position + Vector3.Up*5;
         }

         public void Walk(float z)
         {
             position += forward * z;
         }

         public void Strafe(float x)
         {
             position += left;
         }

         public void Fly(float z)
         {
             position += up;
         }

         public void Rotate(float x, float y, float z)
         {
             forward = Vector3.Transform(forward, Matrix.CreateFromYawPitchRoll(x, y, z));
             left = Vector3.Transform(left, Matrix.CreateFromYawPitchRoll(x, y, z));
             up = Vector3.Transform(up, Matrix.CreateFromYawPitchRoll(x, y, z));
         }

         public void Roll(float z)
         {

         }

         public void Pitch(float x)
         {

         }

         public void Yaw(float z)
         {

         }
     }
}
